package com.wuyan.warriorsoffate.data

import android.content.res.AssetManager
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.wuyan.warriorsoffate.tools.Tools
import com.wuyan.warriorsoffate.ui.theme.WeTheme.Theme.*
import java.lang.StringBuilder
import kotlin.reflect.KProperty

const val names1 =
    "大将刘备军师魏颜延璋循巴晔岱封张苞角宝梁济凯颌勋韩鲁卫任松昭弘辽典韦瑾山海贼严当贾禅双黄忠曹操丕孙权策楙袁术绍周瑜庞逞朱褒马元义统陆逊鲁肃许褚度环夏侯惇渊史慈焉飞诩文丑郭图金旋韩孟达获仁洪纯休伊籍盖法植华彰雄仓正尚真王蔡儒李关羽贵宋勇程远志汜傕樊稠胡轸谭熙审配沮授田丰攸陈琳太纪灵雷薄刚胤朗粲良师懿司兴平龄应登珪糜竺巩怀同桓累珝矢治泰藩凌蒋钦武步骘普综薛敢沢虞翻峻绩乐进于禁牛成昱毛玠宪蒋干群修娇嘉芳廖化乾琬费袆允士"
const val names2 =
    "虔晃董卓旻火扬虎盛丁奉雍闿高诸葛亮瑾鲍隆顾荀彧攸邓览冷苞茂甘宁姜维赵云范沛邢道荣徐庶吕布旷翔蒙贤盗邕杨续昂贵琬索优吴兰谡超兵德玄"
const val names1e =
    "那边一个人也没有环视四周但是，什么发现找到宝箱里面得你不能把所这些都带上要扔掉吗?工具拿使用起作受伤了移动已无法保持着种状态将交给装备解除的傻瓜舍弃就前进抛恢复成为军师被职位入行李中从取出来袋放又回之并去哪部呢。在儿疲乏至极刘全歼拥多同伙士兵体力活效果消失等级提高数达记住撤退狙击突然攻奋斗共防御杀名灭与战胜溃获经验值金粮欢迎晚宿请勿勉强钱够可安休息吧早好今天加油干您！我卖问准少份谢下次再光临武器店谁对让别还需到嗯否畅销货很遗憾吩咐查看登灵增或许走离队地方雇如何以明白列开们营"
const val names1f =
    "若话继续逼毫察觉捉敌怎办马足辛苦事水平尚目程确实陶谦背后叫急电附近河计谋略升麼赶紧讨伐。快点帮助叛贼万岁黄巾抓组织支大始常啊张世商号召感想购买20两1宋勇仁俩会尽抱歉说徐州城太守盔甲难奏功倒较弱伍基础家论替报仇据三堡糜竺哦集义直盼望像样年轻卧病床先生座必代终于身接管告真令兴累歇听求廉危他正躺心哇哈…凭和首领角铁门峡根占青洲哼易池怕死应山内啦往西南-率驻居兄弟步只气小麦收热渴酒曹操者募子陈学过艺参派场指教而外袁术、绍董卓厌唉呀照情况机打败原镇逃遇手关羽飞民众抚追随亲自劳跟谈希"
const val names20 =
    "救洛阳皇帝亡国合做灰反速送梁宁恶孙策草虎牢猛吕布塞便喜此见汉跑破托福总挥食须重整援辞算王充屋定七星刀转归顺赤兔兔日千良驹烟锁刚才逆54变废元决信允处藏剑五3东时言语镶颗非切连补题渤海长其偷究简象梦眺杨标监狱清楚却贾诩由护建胆陷量汜8格爱拴栅栏牵笔宫官似乎新界底联造股势市既美女桃花源姑娘胡靠当瑾阵侯立激意思传玉玺称谓印相它落野忙证混蛋改毕竟忍即吃掌肃遭伴姗迟慢吞暂乡巴佬脸暴政统治淮纪灵八分馆赵云老婆修施妻仓封介镜头广宗结束采毛夷朋友诉项秘密延揽伏龙凤雏妇媳厉抹注害十六挡拦勃冀"
const val names21 =
    "夫豪杰庶单鼓劲投洞窟崩石块路堵炸药诸流浪礼止担扎曾聆贤诲批错誓忠财抢尊敬匠堂因禀忘桥渡孔茅庐谡庵荆哥系F渴际争乱深火乐业郡挪读书沙纷桂旁骗途糊涂久沾谅悔赁顿零陵邢荣谜“拉亚”最丢母憧憬庞楼桑村崔拜访喔络房已睡醒貌均顾知拒绝声招呼昭蜀歹控制族臂留违谣吴该向寂莫未远韩迷虽赞扬璋涪务某产质坚硬扇撞压钢古锐利绵竹恩负依主锋闪间字邪及困男魏吉土概且二暗兆断袭暇容昊险肩付置权寻篡夺父朝命通鄱湖满溢岩特色亮硝木树枝硫磺调北轰惊音摇晃化督瑜侵任眼稽胞葛砦越隐滚冷横苞晋蒙懂犯陆逊盗慎理物恐百"
const val names22 =
    "姓聚玩训签订条约握丕愧九泉历史促君慰祖祠：血承；口惩罚沉默认拘泥节6月台文宣架室员债狼狈旦各寨赋税般臭汇趁冲赢仗比霸听赖喂度逝养性妹予钥匙愿存每弄惫痛棵脚惜划席敢肆狂蹄旗汝彰缍糟司懿覆雷索妖恋载咒左右念辙故议灾征藩撑顽固壤烧毁完祥瑞稍漫旅运奢侈顶坏段短讲降农肯裂祝贺穴殿适宜针疑挑拨敏捷丧廷园异则协扶黎鉴戳玄德炭贵设刻启拯神犹麻痹避卫详臣举站埃玻蠢哭徽祭银邀珠赌符魂丹仙铜棍斧枪戟叉弓偃蛇键球巨矛皮胸胄缠帽超志郭华雄樊稠轸儒蔡邕济薄丰兰胤谭熙凯颜丑蕃配沮授田攸图琳严旋巩龄庆孟循"
const val names23 =
    "怀松桓诩朱泰慈盖凌蒋钦骛鲁宏普薛综阚泽虞翻峻绩洪昂纯褚典韦夏侯敦渊禁晔牛绕辽双昱宪群岱朗矫植嘉乾伊籍禅邓茂范览翔鲍沛盛丁奉雍甘虔荀姜维艾练劫炎柔奇倍竭斯埔庙腾品嘀推孩甥京芳（）隔壁景画片街申预壮I换章抗魔黑嫁添亭另趴庄川罗熊费票宽公形懊游戏拷贝肥坡翼宛智售翼宛智售售售售坡翼宛杜克努克努努智售杜克努克努努努努"
val ShopNames=arrayOf("徐州","洛阳","长安","长安后","南阳","渤海","冀州","长沙","涪水城","成都","晋都城","建业","广陵城","汝南城")
val ShopOffset= listOf(0x390b9,0x390C4,0x390CD,0x390DA,0x390E2,0x390EB,0x390FA,0x39114,0x3911D,0x3912B,0x3913E,0x39146,0x39150,0x39158)
class NesViewModel(data_s:Array<Int>): ViewModel() {
    //原始数据

    private val data=Array(data_s.size){i->
        mutableStateOf(data_s[i])
    }
    //人物信息数组
    val persons=Array(0xd9){ i->
        Person(i)
    }
    //兵力流派数据
    val troops=Array(0x80){i->
        Data2byte(i*2+0x33ee0)
    }
    //道具列表
    val props=Array(0x39){
        Prop(pos = it)
    }
    //武器列表
    val weapon=Array(0x13){
        Weapon(it)
    }
    //防具列表
    val defense=Array(0x17){
        Defense(it)
    }
    //MSP升级乱序
    val msps=Array(16){
        data[0x3B683+it]
    }
    //是否穿墙
    var isWall by DataBoolean({
        data[0x7f337].value==0xff
    },{value->
        if (value){
            data[0x7f337].value=0xff
        }else{
            data[0x7f337].value=0x10
        }
    })
    //初始三杰，分别对别对应刘备、关羽、张飞
    val initPersons=listOf(data[0x3570f],data[0x3570D],data[0x3570e])
    //初始三人对应物品
    val initPersonsProp= listOf(Array(8){
        data[0x35731+it]
    },Array(8){
        data[0x35721+it]
    },Array(8){
        data[0x35729+it]
    })
    //一些替换人物
    val replacePersons=listOf(
        data[0x31AC9],data[0x31AD0],data[0x311B8],data[0x311C0],data[0x31184],data[0x313C0],
        data[0x312AA],data[0x312DD],data[0x312E4],data[0x319B8],data[0x319fa],data[0x31976],
        data[0x31909],data[0x312a3],data[0x313b7],data[0x31772],data[0x31779],data[0x312c5],
        data[0x312f8],data[0x312ff],data[0x3134a],data[0x31351],data[0x371d5],data[0x371c7],data[0x36ebd]
    )
    //一些替换人物对应初始人物番号
    val replacePersonsInit= listOf(10,11,61,59,174,175,153,159,160,184,185,9,8,214,215,65,66,213,169,172,170,173,177,176,157)
    //不能离队人物番号最多7位
    val notLeavePersons=listOf(data[0x3956D],data[0x3956e],data[0x3956f],data[0x39570],data[0x39571]
        ,data[0x39572],data[0x39573])
    //不能解雇武将,共17人
    val notFirePersons=Array(17){
        data[0x39574+it]
    }
    //不可暗杀的敌方武将，3个（可能是8个）
    val notKillPersons=Array(8){
        data[0x3BC6A+it]
    }
    //护身烟步数
    val mistNum=data[0x38c6e]
    //商店列表
    val shops= mutableListOf<Shop>()
    //等级列表
    val dengJis=Array(50){
        Grade(it)
    }

    init {

        for (i in ShopNames.indices){
            var offset=ShopOffset[i]
            val wu= mutableListOf<MutableState<Int>>()
            val daoju=mutableListOf<MutableState<Int>>()
            do {
                wu.add(data[offset])
            }while (data[++offset].value!=0xff)
            ++offset
            do {
                daoju.add(data[offset])
            }while (data[++offset].value!=0xff)
            shops.add(Shop(ShopNames[i],wu,daoju))
        }
    }
    //所有等级
    inner class Grade(id:Int){
        var value by DengJi(id)
    }
    //道具类
    inner class Prop(pos:Int){
        private val offset= data[0x4C080+pos].value.shl(8)+data[0x4c010+pos].value+0x44010
        private val offsetMoney=data[0x32448+pos].value.shl(8)+data[0x323D8+pos].value+0x28010
        var money by Money()
        var name by mutableStateOf("")
        private val nameData= mutableListOf<MutableState<Int>>()
        init {
            var i:Int=offset+2
            while (data[i].value!=0xff){
                nameData.add(data[i])
                ++i
            }
            update()
        }
        fun update() {
            var i=0
            val temp=StringBuilder()
            var c:Int
            while (i<nameData.size){
                when(nameData[i++].value){
                    0x1E->{
                        c=nameData[i++].value
                        if(c<names1e.length){
                            temp.append(names1e[c])
                        }else{
                            break
                        }
                    }
                    0x1f->{
                        c=nameData[i++].value
                        if(c<names1f.length){
                            temp.append(names1f[c])
                        }else{
                            break
                        }
                    }
                    0x20->{
                        c=nameData[i++].value
                        if(c<names20.length){
                            temp.append(names20[c])
                        }else{
                            break
                        }
                    }
                    0x21->{
                        c=nameData[i++].value
                        if(c<names21.length){
                            temp.append(names21[c])
                        }else{
                            break
                        }
                    }
                    0x22->{
                        c=nameData[i++].value
                        if(c<names22.length){
                            temp.append(names22[c])
                        }else{
                            break
                        }
                    }
                    0x23->{
                        c=nameData[i++].value
                        if(c<names23.length){
                            temp.append(names23[c])
                        }else{
                            break
                        }
                    }
                    else->break
                }
            }
            name=temp.toString()
        }
        inner class Money{
            operator fun setValue(prop: NesViewModel.Prop, property: KProperty<*>,value: Int) {
                data[offset+1].value=value.ushr(8)
                data[offset].value=value and 0xff
                data[offsetMoney+1].value= value.ushr(8)
                data[offsetMoney].value=value and 0xff
            }

            operator fun getValue(prop: NesViewModel.Prop, property: KProperty<*>): Int {
                return data[offset+1].value.shl(8)+data[offset].value
            }
        }
    }
    //武器类
    inner class Weapon(pos_:Int){
        private val pos=pos_+0x40
        private val offset= data[0x4C080+pos].value.shl(8)+data[0x4c010+pos].value+0x44010
        private val offsetMoney=data[0x32448+pos].value.shl(8)+data[0x323D8+pos].value+0x28010
        var money by Money()
        var displayAttack by data[0x38613+pos_]
        var trueAttack by TrueAttack(pos_)
        var name by mutableStateOf("")
        private val nameData= mutableListOf<MutableState<Int>>()
        init {
            var i:Int=offset+2
            while (data[i].value!=0xff){
                nameData.add(data[i])
                ++i
            }
            update()
        }
        fun update() {
            var i=0
            val temp=StringBuilder()
            var c:Int
            while (i<nameData.size){

                when(nameData[i++].value){
                    0x1E->{
                        c=nameData[i++].value
                        if(c<names1e.length){
                            temp.append(names1e[c])
                        }else{
                            break
                        }
                    }
                    0x1f->{
                        c=nameData[i++].value
                        if(c<names1f.length){
                            temp.append(names1f[c])
                        }else{
                            break
                        }
                    }
                    0x20->{
                        c=nameData[i++].value
                        if(c<names20.length){
                            temp.append(names20[c])
                        }else{
                            break
                        }
                    }
                    0x21->{
                        c=nameData[i++].value
                        if(c<names21.length){
                            temp.append(names21[c])
                        }else{
                            break
                        }
                    }
                    0x22->{
                        c=nameData[i++].value
                        if(c<names22.length){
                            temp.append(names22[c])
                        }else{
                            break
                        }
                    }
                    0x23->{
                        c=nameData[i++].value
                        if(c<names23.length){
                            temp.append(names23[c])
                        }else{
                            break
                        }
                    }
                    else->break
                }
            }
            name=temp.toString()
        }
        inner class Money{
            operator fun setValue(weapon: NesViewModel.Weapon, property: KProperty<*>,value: Int) {
                data[offset+1].value=value.ushr(8)
                data[offset].value=value and 0xff
                data[offsetMoney+1].value= value.ushr(8)
                data[offsetMoney].value=value and 0xff
            }

            operator fun getValue(weapon: NesViewModel.Weapon, property: KProperty<*>): Int {
                return data[offset+1].value.shl(8)+data[offset].value
            }
        }
        inner class TrueAttack(private val pos: Int) {
            operator fun setValue(weapon: NesViewModel.Weapon, property: KProperty<*>,value: Int) {
                data[pos+0x7E6BA].value=value and 0xff
                data[pos+0x7E6CE].value=value ushr 8 and 0xff
            }

            operator fun getValue(weapon: NesViewModel.Weapon, property: KProperty<*>): Int {
                return data[pos + 0x7E6BA].value + data[pos + 0x7E6CE].value.shl(8)
            }
        }
    }
    inner class Defense(pos_:Int){
        private val pos=pos_+0x59
        private val offset= data[0x4C080+pos].value.shl(8)+data[0x4c010+pos].value+0x44010
        private val offsetMoney=data[0x32448+pos].value.shl(8)+data[0x323D8+pos].value+0x28010
        var money by Money()
        var defense by data[0x7E6E1+pos_+1]
        var name by mutableStateOf("")
        private val nameData= mutableListOf<MutableState<Int>>()
        init {
            var i:Int=offset+2
            while (data[i].value!=0xff){
                nameData.add(data[i])
                ++i
            }
            update()
        }
        fun update() {
            var i=0
            val temp=StringBuilder()
            var c: Int
            while (i<nameData.size){
                when(nameData[i++].value){
                    0x1E->{
                        c=nameData[i++].value
                        if(c<names1e.length){
                            temp.append(names1e[c])
                        }else{
                            break
                        }
                    }
                    0x1f->{
                        c=nameData[i++].value
                        if(c<names1f.length){
                            temp.append(names1f[c])
                        }else{
                            break
                        }
                    }
                    0x20->{
                        c=nameData[i++].value
                        if(c<names20.length){
                            temp.append(names20[c])
                        }else{
                            break
                        }
                    }
                    0x21->{
                        c=nameData[i++].value
                        if(c<names21.length){
                            temp.append(names21[c])
                        }else{
                            break
                        }
                    }
                    0x22->{
                        c=nameData[i++].value
                        if(c<names22.length){
                            temp.append(names22[c])
                        }else{
                            break
                        }
                    }
                    0x23->{
                        c=nameData[i++].value
                        if(c<names23.length){
                            temp.append(names23[c])
                        }else{
                            break
                        }
                    }
                    else->break
                }
            }
            name=temp.toString()
        }
        inner class Money{
            operator fun setValue(defense: NesViewModel.Defense, property: KProperty<*>,value: Int) {
                data[offset+1].value=value.ushr(8)
                data[offset].value=value and 0xff
                data[offsetMoney+1].value= value.ushr(8)
                data[offsetMoney].value=value and 0xff
            }

            operator fun getValue(defense: NesViewModel.Defense, property: KProperty<*>): Int {
                return data[offset + 1].value.shl(8)+ data[offset].value
            }
        }
    }
    //武将数据类
    inner class Person(private val pos:Int){
        //基本数据偏移
        private val offset:Int= data[0x32810 + pos].value + data[0x32910 + pos].value.shl(8)+0x28010
        //中文版偏移地址
        private val dialogueOffset:Int = data[0x54410 + pos].value + data[0x54500 + pos].value.shl(8)+0x4c010
        var force by data[offset]//武力
        var brains by data[offset+1]//智力
        var place by data[offset+2]//活动章节
        val mode by data[offset+3]//武将模型
        val modeColor by data[offset+4]//第一个0是模型颜色(0是红，4是蓝，8是绿，c是绿蓝相间),第二个0是敌将攻击力
        var foeDefense by data[offset+5]//敌将防御力
        var foeTroops by data[offset+6]//敌将固定兵力设定：（流派：00-7F）：0x33EE0-0x33FDF，两个字节为一个流派
        var troops by data[offset+7]//我方武将固定兵力设定：（流派：00-7F）：0x33EE0-0x33FDF，两个字节为一个流派
        var tacticsType by data[offset+8]//策略类型1f为上限最高策略
        var speed by data[offset+9]//武将速度e6说明刘备的速度是230，但武将界面不显示
        private val heads = Array(6){i->
            data[offset+10+i]
        }//武将头像000102030405是武将头像
        private val nameOffsetHeadBg by data[dialogueOffset+16]//武将名字牵引+武将头像背景颜色，中文版作废，不用理它，1蓝，2深蓝，3绿，4粉红，5灰，6红，7黄，8浅黄，9正常颜色，一般特殊头像才用9做背景颜色
        //武将名称数据
        private val nameData= mutableListOf<MutableState<Int>>()
        var name by mutableStateOf("")
            private set
        //对白名称
        var dialogueName by mutableStateOf("")
            private set
        //对白名称数据
        private val dialogueNameData= mutableListOf<MutableState<Int>>()
        var embody by IsEmbody()
        init {
            val buffer= StringBuilder()
            nameData.clear()
            var nameLen=0
            var n= nameOffsetHeadBg.and(0xf0)
            var ch=data[dialogueOffset+17+nameLen]
            while (ch.value!=0xff&&nameLen<3){
                nameData.add(ch)
                if(n.and(0x80)!=0){
                    if (ch.value >= names2.length){
                        break
                    }
                    buffer.append(names2[ch.value])
                }else{
                    if(ch.value >= names1.length){
                        break
                    }
                    buffer.append(names1[ch.value])
                }
                n=n.shl(1)
                ++nameLen
                ch=data[dialogueOffset+17+nameLen]
            }
            name=buffer.toString()
            ++nameLen
            ch=data[dialogueOffset+17+nameLen]
            dialogueNameData.clear()
            while (ch.value!=0xff) {
                dialogueNameData.add(ch)
                ++nameLen
                ch=data[dialogueOffset+17+nameLen]
            }
            dialogueName= getDialogue(dialogueNameData)
        }
        inner class IsEmbody()
        {
            private var _temp=false
            operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
                val temp = data[0x358D7 + pos / 8].value
                _temp=(temp ushr (pos % 8)) and 0x01 == 1
                return _temp
            }

            operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) {
                if (value != _temp) {
                    val temp = data[0x358D7 + pos / 8].value
                    if (value) {
                        data[0x358D7 + pos / 8].value = (0x01 shl (pos % 8)) or temp
                    } else {
                        data[0x358D7 + pos / 8].value = (0x01 shl (pos % 8)) xor temp
                    }

                }
            }
        }
    }
    //根据偏移值获取两个连续数据组成一个16位数据
    inner class Data2byte(private val offset:Int): MutableLiveData<Int>(){
        override fun setValue(value: Int) {
            data[offset].value=value and 0xff
            data[offset+1].value=value ushr 8 and 0xff
            super.postValue(value)
        }

        override fun getValue(): Int {
            return data[offset].value +data[offset+1].value.shl(8)
        }

    }
    //根据一个偏移值的数据返回是否为真
    inner class DataBoolean(private val get:()->Boolean,private val set:(value: Boolean)->Unit){
        operator fun getValue(nesViewModel: NesViewModel, property: KProperty<*>): Boolean {
            return get()
        }

        operator fun setValue(nesViewModel: NesViewModel, property: KProperty<*>,value: Boolean) {
            set(value)
        }

    }
    //商店类
    inner class Shop(val name:String,val weaponIds:List<MutableState<Int>>,val propIds:List<MutableState<Int>>)
    //升级等级
    inner class DengJi(private val pos:Int){
        operator fun setValue(grade: NesViewModel.Grade, property: KProperty<*>,value: Int) {
            data[pos*3+0x3b693+2].value=value.ushr(16)
            data[pos*3+0x3b693+1].value=value.and(0xff00).ushr(8)
            data[pos*3+0x3b693].value=value and 0xff
        }

        operator fun getValue(grade: NesViewModel.Grade, property: KProperty<*>): Int {
            return data[pos*3+0x3b693+2].value.shl(16)+data[pos*3+0x3b693+1].value.shl(8)+data[pos*3+0x3b693].value
        }
    }
    fun refresh(buffer: ByteArray){
        for(i in buffer.indices){
            data[i].value=buffer[i].toInt() and 0xff
        }
        for (i in props.indices){
            props[i].update()
        }
        for (i in weapon.indices){
            weapon[i].update()
        }
        for (i in defense.indices){
            defense[i].update()
        }
    }
    var theme by mutableStateOf(Pink)
    fun nextTheme(){
        theme=when(theme){
            Pink -> Greenery
            Greenery -> Aesthetic
            Aesthetic -> Beauty
            Beauty -> Pink
        }
    }
    fun searchPerson(personName:String):MutableList<Int>{
        val list= mutableListOf<Int>()
        for (i in persons.indices){
            val temp=persons[i].name
            if (temp!=""&&(temp.indexOf(personName)>=0||personName.indexOf(temp)>=0)){
                list.add(i)
            }
        }
        return list
    }
    fun toByteArray(): ByteArray {
        val buffers: ByteArray= ByteArray(data.size){
            return@ByteArray (data[it].value and 0xff).toByte()
        }
        return buffers
    }
private companion object{
    fun getDialogue(data:MutableList<MutableState<Int>>):String{
        val buffer= StringBuilder()
        if (data.isNotEmpty()){
            var i=0
            while (i<data.size&&data[i].value!=0xff){
                if (i+1<data.size){
                    when(data[i].value){
                        0x1e->buffer.append(names1e[data[i+1].value])
                        0x1f->buffer.append(names1f[data[i+1].value])
                        0x20->buffer.append(names20[data[i+1].value])
                        0x21->buffer.append(names21[data[i+1].value])
                        0x22->buffer.append(names22[data[i+1].value])
                        0x23->buffer.append(names23[data[i+1].value])
                    }
                    ++i
                }
                ++i
            }
        }
        return buffer.toString()
    }
}
    val state:WeState=WeState()
}
class NesViewModelBuild: ViewModelProvider.Factory{
    var asset: AssetManager?=null
    constructor(asset: AssetManager){
        this.asset=asset
    }
    var path:String?=null
    constructor(filePath:String){
        this.path=filePath
    }
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(NesViewModel::class.java)) {
            if(asset!=null){
                val buffer= asset!!.open("吞食天地1.NES").readBytes().map { it.toInt() and 0xff}.toTypedArray()
                return NesViewModel(buffer) as T
            }else if (path!=null){
                return NesViewModel(Tools.read(path!!)!!) as T
            }
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}

enum class DisplayMainPage{
    PersonList{
        override fun toString(): String {
            return "武将"
        }
    },
    PropList{
        override fun toString(): String {
            return "道具"
        }
    },
    WeaponList{
        override fun toString(): String {
            return "武器"
        }
    },
    DefenseList{
        override fun toString(): String {
            return "防具"
        }
    },
    SundryList{
        override fun toString(): String {
            return "杂项"
        }
    },
}
enum class DisplayPage{
    Main,
    PersonInfo
}
class WeState{
    //当前显示页面
    var displayPage by mutableStateOf(DisplayMainPage.PersonList)
    //
    val isHex= mutableStateOf(false)
    val personListState= LazyListState(0,0)
    val propsListState= LazyListState(0,0)
    val weaponListState= LazyListState(0,0)
    val defenseListState= LazyListState(0,0)
}
